@extends('admin.common.main')

@section('css')
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
@endsection
@section('cnt')
    <div class="layui-form layuimini-form" lay-filter="example">
        @csrf
        <div class="layui-form-item">
            <label class="layui-form-label required">是否顶级</label>
            <div class="layui-input-block">
                <select name="pid" id="pid" lay-verify="required" lay-filter="aihao">
                    <option value="0" >=顶级菜单=</option>
                    @foreach($data as $item)
                        @if($item->id !=$node->id)
                            @if($item->id ==$node->pid)
                                <option selected value="{{$item->id}}">{{ $item->name }}</option>
                            @else
                                <option value="{{$item->id}}">{{ $item->name }}</option>
                            @endif
                        @endif
                    @endforeach
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">权限名称</label>
            <div class="layui-input-block">
                {{--                lazy 延时绑定 --}}
                <input type="text" name="name" id="name"  value="{{$node->name}}" lay-verify="required"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">路由别名</label>
            <div class="layui-input-block">
                <input type="text" name="route_name" id="route_name"  value="{{$node->route_name}}" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否为菜单</label>
            <div class="layui-input-block">
                <input type="radio" name="is_menu"  value="0" title="否" {{($node->is_menu=='0')?"checked=''":0}}>
                <input type="radio" name="is_menu" value="1" title="是"  {{$node->is_menu=='1'?"checked=''":0}}>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit   lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
@endsection

@section('js')
    <script>
        layui.use(['form','upload','http'], function () {
            var form = layui.form,
                layer = layui.layer,
                http  = layui.http,
                $ = layui.$;
            //监听提交
            form.on('submit(saveBtn)', function (data) {
                console.error(data);
                http.httpajax('{{route('admin.node.update',['id'=>$node->id])}}', data.field,"PUT",function(res) {
                    if(res.code === 200){
                        layer.msg(res.msg,{time:1000,icon:1},function(){
                            // 关闭弹出层
                            layer.close();
                            window.parent.location.reload();//刷新父页面
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                        });
                    }else{
                        layer.msg(res.msg,{time:1000,icon:2});
                    }
                });
            });
        });
    </script>
@endsection

